// crowdfund/order_list/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_list: [],
    page: 1,
    status: -1,
    is_loadding: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
    getApp().page.onLoad(this,t);
    this.get_list()
  },

  updateStatus (t) {
    var status = t.currentTarget.dataset.status
    var that = this
    this.setData({
      status: status,
      order_list: [],
      page: 1,
      is_loadding: 1
    }, function() {
      that.get_list()
    })
  },

  get_list () {
    wx.showLoading({
      title: '加载中...',
    });
    var that = this
    getApp().request({
      url: getApp().api.crowdfund.order_list,
      data: {
          status: that.data.status,
          page: that.data.page
      },
      success: data => {
        console.log(data)
        if (data.code == 0) {
          if (data.data.list && data.data.list.length > 0) {
            that.setData({
              order_list: that.data.order_list.concat(data.data.list),
              page: ++that.data.page
            })
          } else {
            that.setData({
              is_loadding: 0
            })
          }
        }
      },
      complete: () => {
          wx.hideLoading();
      }
    });
  },

  onReachBottom () {
    if (this.data.is_loadding == 1) {
      this.get_list()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    getApp().page.onShow(this);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  orderConfirm: function(e) {
    var a = this;
    getApp().core.showModal({
        title: "提示",
        content: "是否确认已收到货？",
        cancelText: "否",
        confirmText: "是",
        success: function(t) {
            if (t.cancel) return !0;
            t.confirm && (getApp().core.showLoading({
                title: "操作中"
            }), getApp().request({
                url: getApp().api.crowdfund.confirm,
                data: {
                    order_id: e.currentTarget.dataset.id
                },
                success: function(t) {
                    getApp().core.hideLoading(), getApp().core.showToast({
                        title: t.msg
                    });
                    if (0 == t.code) {
                      a.setData({
                        order_list: [],
                        page: 1,
                        is_loadding: 1
                      }, function () {
                        a.get_list()
                      })
                    }
                }
            }));
        }
    });
  }
})